home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 432_01 / ptmid3 / handles.c < prev    next >
C/C++ Source or Header  |  1994-06-29  |  2KB  |  65 lines

  1. /*
  2.  * handles.c: Adds the ability to use more handles under Turbo C 2.0
  3.  * Requires my patched version of Turbo C 2.0, where the _openfd and
  4.  * close thingies from the FILES2 and CLOSE modules have been altered to
  5.  * work with 40 files maximum instead of 20.
  6.  * Urgh this is so ugly. Neatness requires assembly.
  7.  * Idea based on routines by W. Metzenthen
  8.  *
  9.  * Author: Andrew Scott
  10.  *
  11.  * Date: 10/2/1994 ver 0.1
  12.  */
  13.  
  14. #include <dos.h>
  15. #include <mem.h>
  16.  
  17. /**
  18.  ** MAX_HAND must be greater than 20. Note than greater than 127 may
  19.  ** cause some networks to do very odd things. Turbo C has an upper
  20.  ** maximum of 257. Borland C++ 3.0 has a maximum of 255 I think.
  21.  ** The patched version of Turbo C 2.0 can handle (pun) MAX_HAND upto
  22.  ** 40. Further patching is required for larger values.
  23.  **/
  24. #define MAX_HAND 40
  25.  
  26. typedef unsigned char far *blocktype;
  27. typedef unsigned short far *psptype;
  28.  
  29. /**
  30.  ** file_table is the storage space for the new file handle table. It is
  31.  ** given an extra 15 bytes of size to ensure that when the start of it
  32.  ** is decided (ie. shifted to a segment boundary) the end doesn't
  33.  ** overflow the size of the array.
  34.  **/
  35. static unsigned char file_table[MAX_HAND + 15];
  36.  
  37. /*
  38.  * increase_handles: When called, sets up the file table for MAX_HAND
  39.  * handles to be used by Turbo C.
  40.  *
  41.  * date: 10/2/1994
  42.  */
  43. void increase_handles() {
  44.   unsigned char junk[MAX_HAND - 20];
  45.     unsigned short newpsp[3], psp = _psp;
  46.   unsigned blockoff, blockseg;
  47.  
  48.     /** Put blockseg:0000 to be start of file_table **/
  49.     blockseg = FP_SEG((blocktype) file_table);
  50.     if ((blockoff = FP_OFF((blocktype) file_table)) & 0xF)
  51.         blockseg++;
  52.     blockseg += blockoff >> 4;
  53.  
  54.   memset(junk, 0xFF, MAX_HAND - 20); /** Set up junk for invalid files **/
  55.   newpsp[0] = MAX_HAND; /** Set up new PSP information **/
  56.   newpsp[1] = 0;
  57.   newpsp[2] = blockseg;
  58.  
  59.   /** Move all the information into position **/
  60.   movedata(psp, 0x0018, blockseg, 0, 20);
  61.   movedata(FP_SEG((blocktype) junk), FP_OFF((blocktype) junk),
  62.     blockseg, 0x0014, MAX_HAND - 20);
  63.   movedata(FP_SEG((psptype) newpsp), FP_OFF((psptype) newpsp), psp, 0x32, 6);
  64. }
  65.